<template>
    <div>
       <h1>抄送人管理</h1>
       <el-row>
        <el-button type="primary" round  @click="drawer = true">添加</el-button>
      </el-row>
  
      <el-drawer
        title="添加抄送人"
        :visible.sync="drawer"
        :direction="direction"
        :before-close="handleClose">
        <el-input v-model="email_copy" placeholder="请输入抄送人的邮箱"></el-input>
        <el-row>
          <el-button type="primary" round class="button" @click="add">添加</el-button>
        </el-row>
  
      </el-drawer>
  
      <el-table :data="user_list">
          <el-table-column label="抄送人邮箱" prop="email_copy"> </el-table-column>
        <el-table-column label="操作" width="200px">
          <template slot-scope="scope">
            <el-button size="mini" @click="update(scope.row.id)">编辑</el-button>
            <el-button size="mini" type="danger" @click="del(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
       </el-table>
  
      <el-dialog
    title="修改抄送人"
    :visible.sync="dialogVisible"
    :before-close="handleClose">
    <el-input v-model="list2.email_copy" placeholder="请输入类型"></el-input>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="xiugai">确 定</el-button>
    </span>
  </el-dialog>
    </div>
  </template>
  
  <script>
  export default {
          data(){
      return{
        user_list:[],
        drawer:false,
        dialogVisible:false,
        direction: 'rtl',
        email_copy:"",
  
        list2:{
          id:"",
          email_copy:"",
        }
  
      }
    },
    mounted(){
      this.getData()
      
    },
    methods:{
      xiugai(){
        this.$axios.put("works/api/v1/addcopy/" + this.list2.id +  "/",{
          email_copy:this.list2.email_copy
          },{
             headers:{
            token:localStorage.getItem("token")
          }
          })
        .then(ree=>{
          if (ree.data.cdoe == 200){
            alert(ree.data.msg)
            this.getData()
          }else{
            alert(ree.data.msg)
          }
        }).catch(ss=>{
          console.log(ss)
        })
  
      },
      update(id){
        this.dialogVisible = true
        this.$axios.get("works/api/v1/addcopy/" + id +  "/",{
          headers:{
            "token":localStorage.getItem("token")}
          }
        )
        .then(ree=>{
          this.list2 = ree.data.data
        }).catch(ss=>{
          console.log(ss)
        })
      },
            handleClose(done) {
          this.$confirm('确认关闭？')
            .then(_ => {
              done();
            })
            .catch(_ => {});
        },
  
  
      add(){
        this.$axios.post("works/api/v1/addcopy/",{
          email_copy:this.email_copy
        },{
          headers:{
            "token":localStorage.getItem("token")
          }
        }).then(ree=>{
          if (ree.data.code == 200){
            alert(ree.data.msg)
            this.getData()
          }else{
            alert(ree.data.msg)
          }
        }).catch(ss=>{
          console.log(ss)
        })
      },
      del(id){
        this.$axios.delete("works/api/v1/addcopy/" + id + "/",{
          headers:{
            "token":localStorage.getItem("token")
          }
        })
        .then(ree=>{
          if (ree.data.code == 200){
            alert(ree.data.msg)
            this.getData()
          }else{
            alert(ree.data.msg)
          }
        }).catch(ss=>{
          console.log(ss)
        })
      },
      getData(){
          this.$axios.get("works/api/v1/addcopy/",{
            'headers':{
                  'token':localStorage.getItem("token")
              }
          })
      .then(ree=>{
        this.user_list = ree.data.data
      }).catch(ss=>{
        console.log(ss)
      })
      }
        
    },
    
  
  }
  </script>
  
  <style>
  
  </style>